import java.awt.*;

public class Explosion {
    private static final int MAX_FRAMES = 20;

    private int x, y;
    private int frame;
    private boolean finished;

    public Explosion(int x, int y) {
        this.x = x;
        this.y = y;
        this.frame = 0;
        this.finished = false;
    }

    public void update() {
        frame++;
        if (frame >= MAX_FRAMES) {
            finished = true;
        }
    }

    public void draw(Graphics2D g2d) {
        if (finished) return;

        float progress = (float) frame / MAX_FRAMES;

        // 计算爆炸大小
        int size = (int) (60 * progress * (2 - progress));

        // 计算颜色
        int alpha = (int) (255 * (1 - progress));
        Color color = new Color(255, 165, 0, alpha);

        // 绘制爆炸效果
        g2d.setColor(color);
        g2d.fillOval(x + 30 - size/2, y + 30 - size/2, size, size);

        // 绘制内部光晕
        alpha = (int) (200 * (1 - progress));
        color = new Color(255, 255, 0, alpha);
        g2d.setColor(color);
        g2d.fillOval(x + 30 - size/4, y + 30 - size/4, size/2, size/2);
    }

    public boolean isFinished() {
        return finished;
    }
}    